package com.ihrm.demo;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;

import java.text.SimpleDateFormat;
import java.util.Date;

public class ParseJwtTest1 {

    /**
     * 解析JwtToken字符串
     *
     * @param args
     */
    public static void main(String[] args) {
        String token = "eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiI4OCIsInN1YiI6IuadjueZvSIsImlhdCI6MTY4ODUzODkzMSwiZXhwIjoxNjg4NTM4OTkxLCJyb2xlcyI6ImFkbWluIiwibG9nbyI6ImxvZ28ucG5nIn0.eiWafrxiTYEVPX9grZU_BtUW9Yrc2vRfY6kNIXbIBfA";
        Claims claims = Jwts.parser().setSigningKey("Awen").parseClaimsJws(token).getBody();
        System.out.println("id:" + claims.getId());
        System.out.println("subject:" + claims.getSubject());
        System.out.println("roles:" + claims.get("roles"));
        System.out.println("logo:" + claims.get("logo"));
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        System.out.println("签发时间:" + sdf.format(claims.getIssuedAt()));
        System.out.println("过期时间:" + sdf.format(claims.getExpiration()));
        System.out.println("当前时间:" + sdf.format(new Date()));
    }

}
